// @ts-ignore
/* eslint-disable */
import { request } from 'umi';
import { transformList2Tree } from '@/utils/utils'

/** 获取部门列表 GET /api/v1/dict/:id */
export async function dictInfo(id: number) {
  return request('/api/v1/dict/' + id, {
    method: 'GET'
  });
}

/** 获取部门列表 GET /api/v1/dict */
export async function dictList(options?: { [key: string]: any }) {
  return request('/api/v1/dict/', {
    method: 'GET',
    params: {...(options || {})},
  });
}

export async function dictParent(
  options?: { [key: string]: any },
) {
  return request<API.AuthorityList>('/api/v1/dict', {
    method: 'GET',
    ...(options || {}),
  }).then((res) => transformList2Tree(res.data));
}

/** 新建部门 dict /api/v1/dict */
export async function dictAdd(body: any, options?: { [key: string]: any }) {
  return request<API.CustomerResponse<any>>('/api/v1/dict/', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 更新部门 PUT /api/v1/dict */
export async function dictUpdate(id: number, body: any, options?: { [key: string]: any }) {
  return request<API.CustomerResponse<any>>(`/api/v1/dict/${id}`, {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
    },
    data: body,
    ...(options || {}),
  });
}

/** 新建部门 dict /api/v1/dict */
export async function dictDelete(id: number) {
  return request<API.CustomerResponse<any>>('/api/v1/dict/1', {
    method: 'DELETE',
    headers: {
      'Content-Type': 'application/json',
    }
  });
}

/** 获取部门列表 GET /api/v1/dict */
export async function dictDataList(options?: { [key: string]: any }) {
  return request('/api/v1/dict/1/data', {
    method: 'GET',
    params: {...(options || {})},
  });
}
